package com.example.xiaoxueqixiangmu.jiemian;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xiaoxueqixiangmu.R;
import com.example.xiaoxueqixiangmu.utils.Constant;

import java.util.ArrayList;
import java.util.HashMap;


public class MyListViewAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<HashMap<String,String>> dataArray;

    public MyListViewAdapter(Context context,ArrayList<HashMap<String,String>> dataArray){
        this.context = context;
        this.dataArray = dataArray;
    }

    @Override
    public int getCount() {
        return dataArray.size();
    }

    @Override
    public Object getItem(int position) {
        return dataArray.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View item = layoutInflater.inflate(R.layout.item_lv,null,false);
        HashMap<String, String> hashMap = dataArray.get(position);
        TextView trainsNo = item.findViewById(R.id.trainsNo);
        TextView txtStartTime = item.findViewById(R.id.txtStartTime);
        TextView txtArriveTime = item.findViewById(R.id.txtArriveTime);
        TextView txtSeats = item.findViewById(R.id.txtSeats);

        trainsNo.setText(hashMap.get("trainsNo"));
        txtStartTime.setText(hashMap.get("txtStartTime"));
        txtArriveTime.setText(hashMap.get("txtArriveTime"));
        txtSeats.setText(hashMap.get("txtSeats"));

        return item;
    }
}
